clear all


set more off

scalar def lowlim		=0.85
scalar def highlim		=5

cd "$revdta"

**********************************************************************************************
use "Full_Panel_2b.dta", clear
keep if sample_analytic==1  & educ <= 2

*bysort newid: egen everSSI=max(tr_ssi >0 & tr_ssi != . & DI ==0)
*bysort newid: egen everboth=max(tr_ssi >0 & DI==1)
*drop if everSSI ==1 
*drop everSSI

gen emp = hours >=1500 & hours != .
*bysort newid: egen everworkhealthy=max(emp == 1 & DS == 0)
*keep if everworkhealthy == 1 & everSSI == 0
*drop everworkhealthy


cd "$out"

drop age2
gen sp_dis = sp_DS==1 | sp_DS==2
gen retired = empst == 4
gen part_full = lw!=. & hours >=1500 
gen part_part = lw !=. & hours < 1500 & hours >=500

gen sp_part_full = sp_lw !=. & sp_hours >=1500
gen sp_part_part = sp_lw != . & sp_hours < 1500 & sp_hours >=500

gen 	age2=age^2
replace age2=age2/100
/*
/*Probably food outliers*/
replace food=. if food>1199987		
replace fout=. if food>129999
egen totfood=rsum(food fout)
*/
*replace rent=0.06*house if rent==0 & house>0
/*
egen spending=rsum(totfood health educexp util childcare transport rent homeins)
replace spending=spending/price
*/
gen lc=ln(spending)

replace lc = . if year<=1996
keep if year > 1996
tempfile temp
save `temp',replace

gen 	scale=1+0.5*(fsize-kids-1)+0.3*kids		/*OECD modified scale*/

		
replace lc=lc-ln(scale)

gen mod_DI=mod*DI
gen sev_DI=sev*DI

gen mod_work = mod*part_full
gen sev_work = sev*part_full

gen spdis_spwork =sp_dis*sp_part_full

gen DSDI0 =DS==0 &DI==1
gen DSDI1 =DS==1 &DI==1
gen DSDI2 = DS==2 &DI==1

label var mod "Mod. Dis."
label var sev "Sev. Dis."
label var part_full "FT Work"
label var part_part "PT Work"
label var mod_work "(Mod. Dis.)X(Work)"
label var sev_work "(Sev. Dis.)X(Work)"
label var sp_dis "Spouse Dis."
label var sp_part_full "Spouse FT Work"
label var sp_part_part "Spouse PT Work"
label var spdis_spwork "(Spouse Dis.)X(Spouse Work)"
label var DSDI1 "(Mod. Dis)X(DI)"
label var DSDI2 "(Sev. Dis)X(DI)"
******* Auxiliary regression Table 4 Panel A ********

*xi:   reg lc sev mod sev_DI mod_DI DI part age age2 sp_dis sp_part  i.year if married==1 & birthy >=1945,				vce(cluster newid) 

*Specification 1
* reg lc i.DS#i.part i.sp_dis#i.sp_part DI DSDI1 DSDI2 age age2 i.year if married==1 & birthy >=1945,				vce(cluster newid) 
* reg lc mod sev  part mod_work sev_work sp_dis sp_part spdis_spwork DI DSDI1 DSDI2 age age2 i.year if married==1  & birthy >=1945 ,	vce(cluster newid) 

 *Main spec:
 gen part_full_married = part_full*married
 gen part_full_single= part_full*(1-married)
 gen part_part_married = part_part*married
 gen part_part_single= part_part*(1-married)
 gen mod_single = mod*(1-married)
 gen sev_single = sev*(1-married)
 gen mod_married = mod*(married)
 gen sev_married = sev*(married)
 gen DSDI2_single = DSDI2 * (1-married)
 gen DSDI1_single = DSDI1 * (1-married)
 gen DSDI0_single = DSDI0 * (1-married)
 gen DSDI2_married = DSDI2 * (married)
 gen DSDI1_married = DSDI1 * (married)
 gen DSDI0_married = DSDI0 * (married)
 gen DSDI_single = DS*DI*(1-married)
 gen DSDI_married = DS*DI*(married)
 gen DI_single = DI*(1-married)
 gen DI_married = DI*(married)
 gen age_single = age*(1-married)
 gen age2_single = age2*(1-married)
 gen age_married = age*(married)
 gen age2_married = age2*(married)
 
 gen part_full_mod = part_full*mod
 gen part_full_sev= part_full*sev
 gen part_full_DS= part_full*DS
 gen part_part_mod = part_part*mod
 gen part_part_sev= part_part*sev
 gen part_part_DS= part_part*DS
 
 gen sp_part_full_dis = sp_part_full*sp_dis
 gen sp_part_part_dis= sp_part_part*sp_dis
 
  reg lc mod_single sev_single  part_full_single part_part_single DSDI0_single DSDI1_single DSDI2_single married mod_married sev_married  part_full_married   part_part_married part_full_mod part_full_sev part_part_mod part_part_sev sp_dis sp_part_full sp_part_part sp_part_full_dis sp_part_part_dis DSDI0_married DSDI1_married DSDI2_married age_single age2_single age_married age2_married i.year,	vce(cluster newid) 
*  reg lc mod sev  part_full##married part_part##married sp_dis sp_part_full sp_part_part DI DSDI1 DSDI2 age age2 i.year,	vce(cluster newid) 
estout using "consmoments_all.txt", cells("b se") mlabels(,none) collabels(,none) replace	 drop(*year* _cons age*)
estout using "consmoments_single.txt", cells("b se") mlabels(,none) collabels(,none) replace	 drop(*year* *married* _cons age* sp_*)
estout using "consmoments_married.txt", cells("b se") mlabels(,none) collabels(,none) replace	 drop(*year* *single* _cons age*)



  reg lc DS part_full part_part DI married part_full_DS part_part_DS sp_dis sp_part_full sp_part_part sp_part_full_dis sp_part_part_dis age age2 i.year,	vce(cluster newid) 
*  reg lc mod sev  part_full##married part_part##married sp_dis sp_part_full sp_part_part DI DSDI1 DSDI2 age age2 i.year,	vce(cluster newid) 
estout using "consmoments_simple_all.txt", cells("b se") mlabels(,none) collabels(,none) replace	 drop(*year* _cons age* married)

coefplot, keep(mod sev  part sp_dis sp_part DI DSDI1 DSDI2)
  graph export  "logcons_regcoefs.pdf", replace
  



*  di "Implicit insurance value of DI" "    " _b[sev_DI]+_b[DI]
****This is (E(c|L=2,DI=1)-E(c|L=2,DI=0))
*matrix V=e(V)
*di sqrt(V[3,3]+V[5,5]+2*V[3,5])

**********************************************************************************************


